SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.DnnProduct_GetSchedule
 @Server varchar(150)
AS
BEGIN
SELECT
  S.*
  , (SELECT max(S1.NextStart)
   FROM dbo.DnnProduct_ScheduleHistory S1
   WHERE S1.ScheduleID = S.ScheduleID) as NextStart
 FROM dbo.DnnProduct_Schedule S
 WHERE
  (@Server IS NULL OR S.Servers LIKE '%,' + @Server + ',%' OR S.Servers IS NULL)
END
GO
